<template>
  <a-layout-content>
    <div class="container-fluid">
      <div class="row">
        <div class="col">
          <el-table
            :data="share.slice((currentPage-1)*pagesize,currentPage*pagesize)"
            style="width: 100%"
            :default-sort="{prop: 'examine', order: 'descending'}"
            class="bg-info"
          >
            <el-table-column prop="examine" sortable fixed label="审核">
              <template slot-scope="scope">
                <button
                  class="btn"
                  :class="btnclass(scope.row.examine).c"
                  type="button"
                  v-text="btnclass(scope.row.examine).n"
                  @click="submit(scope.row)"
                ></button>
              </template>
            </el-table-column>
            <el-table-column prop="name" label="名称"></el-table-column>
            <el-table-column prop="info" label="介绍"></el-table-column>
            <el-table-column prop="imageurl" label="图片">
              <template slot-scope="scope">
                <figure class="figure">
                  <img
                    :src="scope.row.imageurl"
                    class="figure-img img-fluid rounded"
                    alt="A generic square placeholder image with rounded corners in a figure."
                  />
                </figure>
              </template>
            </el-table-column>
            <el-table-column prop="videourl" label="视频">
              <template slot-scope="scope">
                <figure class="figure">
                  <video
                    :src="scope.row.videourl"
                    controls
                    height="360"
                    width="500"
                    class="figure-img img-fluid rounded"
                    alt="A generic square placeholder image with rounded corners in a figure."
                  />
                </figure>
              </template>
            </el-table-column>
            <el-table-column prop="createAt" sortable label="创建时间"></el-table-column>
            <el-table-column type="expand">
              <template slot-scope="scope">
                <form>
                  <div class="form-group row">
                    <label for="staticEmail" class="col-sm-2 col-form-label">用户名称</label>
                    <div class="col-sm-10" v-text="scope.row.username"></div>
                  </div>
                  <div class="form-group row">
                    <label for="inputPassword" class="col-sm-2 col-form-label">用户id</label>
                    <div class="col-sm-10" v-text="scope.row.uid"></div>
                  </div>
                  <div class="form-group row">
                    <label for="inputPassword" class="col-sm-2 col-form-label">回复数</label>
                    <div class="col-sm-10" v-text="scope.row.comments"></div>
                  </div>
                  <div class="form-group row">
                    <label for="inputPassword" class="col-sm-2 col-form-label">观看数</label>
                    <div class="col-sm-10" v-text="scope.row.watch"></div>
                  </div>
                  <div class="form-group row">
                    <label for="inputPassword" class="col-sm-2 col-form-label">点赞数</label>
                    <div class="col-sm-10" v-text="scope.row.fabulous"></div>
                  </div>
                </form>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[4, 50, 100, this.share.length]"
        :page-size="4"
        layout="total, sizes, prev, pager, next, jumper"
        :total="this.share.length"
      ></el-pagination>
    </div>
  </a-layout-content>
</template>

<script>
import { asyncshare, asyncexamineshare } from "@/plugins/api.js";
export default {
  name: "share",
  data() {
    return {
      pagesize: 4,
      currentPage: 1,
      paths: [
        {
          name: "作品",
          path: "/share/index"
        }
      ],
      share: []
    };
  },
  async mounted() {
    await this.start();
  },
  methods: {
    handleSizeChange(val) {
      this.pagesize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
    },
    async start() {
      this.share = await asyncshare();
    },
    async submit(row) {
      const f = {
        ID: row.ID
      };
      let text = 1;
      if (row.examine) {
        f.examine = 0;
        text = "审批为合格";
      } else {
        f.examine = 2;
        text = "审批为不合格";
      }
      this.$confirm(text, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async () => {
          await asyncexamineshare(f);
          this.$message({
            type: "success",
            message: "审批成功!"
          });
          await this.start();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    btnclass(i) {
      switch (i) {
        case 0:
          return {
            c: "btn-success",
            n: "已审核"
          };
        case 1:
          return {
            c: "btn-info",
            n: "待审核"
          };
        case 2:
          return {
            c: "btn-danger",
            n: "不通过"
          };
        default:
          return {
            c: "btn-danger",
            n: "不通过"
          };
      }
    }
  }
};
</script>
